Linux查找文件中的字符串命令 |
您所在的位置:网站首页 › linux 命令搜索 › Linux查找文件中的字符串命令 |
grep -nr 'archermind'
-r, --recursive Read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -d recurse option.
-n, --line-number Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)
grep介绍 (1)grep 的一般格式为 grep [options] 基本正则表达式 [文件] 字符串参数最好采用是双引号括,一是以防被误解为shell命令,二是可以用来查找多个单词组成的字符串 -c:只输出匹配行的记数 -i:不区分大小写(只适用于单个字符) -h:查询多个文件时不显示文件名 -H:只显示文件名 -l:查询多文件时只输出包含匹配字符的文件名 -n:只显示匹配行及其行号 -s:不显示不存在或无匹配文本的错误信息。 -v:显示不包含匹配文本的所有行。 (2)举例说明: grep ^[^210] myfile 匹配myfile中以非2、1、0开头的行 grep "[5-8][6-9][0-3]" myfile 匹配myfile中第一位为5|6|7|8,第二位6|7|8|9,第三位为0|1|2|3的三个字符的行 grep "4\{2,4\}" myfile 匹配myfile中含有44,444或4444的行 grep "\?" myfile匹配myfile中含有任意字符的行 (3)grep命令类名 [[:upper:]] 表示[A-Z] [[:alnum:]] 表示[0-9a-zA-Z] [[:lower:]] 表示[a-z] [[:space:]] 表示空格或者tab键 [[:digit:]] 表示[0-9] [[:alpha:]] 表示[a-zA-Z] 如:grep "5[[:digit:]][[:digit:]]" myfile 匹配myfile中含有5开头接下去两位都是数字的行。 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |